#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

typedef struct node
{
	int data;
	struct node* left;
	struct node* right;
}node;

node* create()
{
	node* p;
	int x;
	printf("Enter data(-1 for no node):");
	scanf("%d",&x);
	p=(node*)malloc(sizeof(node));
	p->data=x;
	if(x!=-1)
	{
		printf("Enter left child of %d:\n",x);
		p->left=create();
		printf("Enter right child of %d:\n",x);
		p->right=create();
	}
	else
	{
		p->left=NULL;
		p->right=NULL;
	}
	return p;
}

void preorder(node* t)
{
	if(t->data!=-1)
	{
		printf("%d",t->data);
		preorder(t->left);
		preorder(t->right);
	}
}

void inorder(node* t)
{
	if(t->data!=-1)
	{
		inorder(t->left);
		printf("%d",t->data);
		inorder(t->right);
	}
}

void postorder(node* t)
{
	if(t->data!=-1)
	{
		postorder(t->left);
		postorder(t->right);
		printf("%d",t->data);
	}
}

void main()
{
	node* root;
	//clrscr();
	system("cls");
	root=create();
	printf("\nThe preorder traversal of tree is:");
	preorder(root);
	printf("\nThe inorder traversal of tree is:");
	inorder(root);
	printf("\nThe postorder traversal of tree is:");
	postorder(root);
	getch();
}